package com.website.web.back.controller.website;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.website.common.annotation.Log;
import com.website.common.enums.BusinessType;
import com.website.custom.domain.WNotice;
import com.website.custom.service.IWNoticeService;
import com.website.common.core.controller.BaseController;
import com.website.common.core.domain.AjaxResult;
import com.website.common.utils.poi.ExcelUtil;
import com.website.common.core.page.TableDataInfo;

/**
 * 广播Controller
 * 
 * @author ruoyi
 * @date 2024-12-03
 */
@Controller
@RequestMapping("/back/custom/notice")
public class WNoticeController extends BaseController
{
    private String prefix = "back/website/notice";

    @Autowired
    private IWNoticeService wNoticeService;

    @RequiresPermissions("system:notice:view")
    @GetMapping()
    public String notice()
    {
        return prefix + "/notice";
    }

    /**
     * 查询广播列表
     */
    @RequiresPermissions("system:notice:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(WNotice wNotice)
    {
        startPage();
        List<WNotice> list = wNoticeService.selectWNoticeList(wNotice);
        return getDataTable(list);
    }

    /**
     * 导出广播列表
     */
    @RequiresPermissions("system:notice:export")
    @Log(title = "广播", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(WNotice wNotice)
    {
        List<WNotice> list = wNoticeService.selectWNoticeList(wNotice);
        ExcelUtil<WNotice> util = new ExcelUtil<WNotice>(WNotice.class);
        return util.exportExcel(list, "广播数据");
    }

    /**
     * 新增广播
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存广播
     */
    @RequiresPermissions("system:notice:add")
    @Log(title = "广播", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(WNotice wNotice)
    {
        return toAjax(wNoticeService.insertWNotice(wNotice));
    }

    /**
     * 修改广播
     */
    @RequiresPermissions("system:notice:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        WNotice wNotice = wNoticeService.selectWNoticeById(id);
        mmap.put("wNotice", wNotice);
        return prefix + "/edit";
    }

    /**
     * 修改保存广播
     */
    @RequiresPermissions("system:notice:edit")
    @Log(title = "广播", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(WNotice wNotice)
    {
        return toAjax(wNoticeService.updateWNotice(wNotice));
    }

    /**
     * 删除广播
     */
    @RequiresPermissions("system:notice:remove")
    @Log(title = "广播", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(wNoticeService.deleteWNoticeByIds(ids));
    }
}
